<template>
  <div class="box">
    <header class="header">
      <van-nav-bar
        title="确认订单"
        left-arrow
        @click-left="$router.back()"
      />
    </header>
    <div class="content">
      <van-cell v-if="flag" @click="toAdrsslist"   :title="name + '' + tel"  size="large" is-link  :label="showAddress"  />
      <van-cell v-else title="请添加收获人信息" @click="toAdrsslist"  size="large" is-link />
      <van-card
        v-for="item of orderlist"
        :key="item.orderid"
        :num="item.num"
        :price="item.originprice"
        :title="item.proname"
        :thumb="item.img1"
      />
      
      <van-submit-bar :price="discount * 100" button-text="立即支付" @submit="onSubmit" >
        <!-- <van-tag type="primary">原价标签</van-tag> -->
        
        原价:<del>￥{{newPirce}}</del> 
        <template #tip>
          打折后优惠 - {{newPirce - discount}} 元
        </template>
      </van-submit-bar>
    </div>
  </div>
</template>
<script>
import Vue from 'vue'
import { NavBar, Card, Cell, CellGroup , SubmitBar , Tag } from 'vant'
import { confirmOrder } from '@/api/order'
Vue.use(NavBar)
Vue.use(Card)
Vue.use(Cell)
Vue.use(CellGroup)
Vue.use(SubmitBar);
Vue.use(Tag);
export default {
  data () {
    return {
      orderlist: [],
      flag: false ,// 判断有没有订单的地址信息
      name: '',
      tel: '',
      province: '',
      city: '',
      county: '',
      addressDetail: ''
    }
  },
  computed: { // ********************************
    showAddress () {
      let str = ''
      this.province === this.city
        ? str = this.province + this.county + this.addressDetail
        : str = this.province + this.city + this.county + this.addressDetail
      return str
    } ,
    newPirce(){
      return this.orderlist.reduce((sum , item) => {
        return sum + item.originprice * item.num * 1 
      }, 0 )
    },
    discount(){
        return this.orderlist.reduce((sum , item) => {
        return Math.floor( sum + item.originprice * item.discount / 10  * item.num  * 1 )  
      }, 0 )
    }
  },
  mounted () {
    
    confirmOrder({
      userid: localStorage.getItem('userid'),
      time: this.$route.params.time // 动态获取参数

    }).then(res => {
        // console.log(this.$route);
      console.log(res.data)
      this.orderlist = res.data.data
      console.log(this.orderlist[0].originprice * 9  / 10 * 1 , 222)
      this.flag = res.data.flag
      // ********************************
      // 收货人信息
      this.name = res.data.address.name
      this.tel = res.data.address.tel
      this.province = res.data.address.province
      this.city = res.data.address.city
      this.county = res.data.address.county
      this.addressDetail = res.data.address.addressDetail
      
    })
    
  },
  methods:{
    
      toAdrsslist(){
          this.$router.push('/orderaddresslist/' + this.$route.params.time)
      },
      onSubmit(){

      },
    
  }
}
</script>

<style lang="stylus"  scoped>
.span11{
  color: blue
}
</style>